// 包含应用所有的请求函数
// 返回值是promise
import ajax from "./ajax";
// import jsonp from "jsonp";
// import { message } from "antd";

// 登录接口
// export function req(username, password) {
//   return ajax("/login", { username, password }, "POST");
// }

export const reqLogin = (username, password) =>
  ajax("/login", { username, password }, "POST");

//   添加用户
export const reqAddUser = (user) => ajax("/manage/user/add", user, "POST");

//获取一级或二级的分类的列表
export const reqCategorys = (parentId) =>
  ajax("/manage/category/list", { parentId });

// 添加分类
export const reqAddCategory = (categoryName, parentId) =>
  ajax("/manage/category/add", { categoryName, parentId }, "POST");
// 更新分类

export const requpdateCategory = (categoryId, categoryName) =>
  ajax("/manage/category/update", { categoryId, categoryName }, "POST");

//获取一个分类
export const reqCateGory = (categoryId) =>
  ajax("/manage/category/info", { categoryId });

//获取商品分页列表
export const reqProducts = (pageNum, pageSize) =>
  ajax("/manage/product/list", { pageNum, pageSize });

//更新商品的状态
export const reqUpdateStatus = (productId, status) =>
  ajax("/manage/product/updateStatus", { productId, status });

//搜索商品分页列表
export const reqSearchProducts = (pageNum, pageSize, searchName, searchType) =>
  ajax("/manage/product/search", {
    pageNum,
    pageSize,
    [searchType]: searchName,
  });

//获取所有角色的列表
export const reqRoles = () => ajax("/manage/role/list");

//添加角色列表
export const reqAddRoles = (rolename) =>
  ajax("/manage/role/list", { rolename }, "POST");
//更新角色
export const reqUpdateRole = (role) =>
  ajax("/manage/role/update", role, "POST");

//获取所有用户列表
export const reqUsers = () => ajax("/manage/user/list");
//删除用户
export const reqDeleteUser = (userId) =>
  ajax("/manage/user/delete", { userId }, "POST");
//添加用户或更新
export const addorUpdateUser = (user) =>
  ajax("/manage/user/list" + (user.id ? "update" : "add"), user, "POST");
// jsonp的接口请求
// export const reqWeather = (city) => {
//   return new Promise((resolve, reject) => {
//     const url = `https://api.map.baidu.com/weather/v1/?district_id=420100&data_type=all&ak=AIXYzMzOXVbnSNhlpSfj6WGHNxuzKIfu&output=json`;
//     jsonp(url, {}, (err, data) => {
//       console.log(err, data);
//       if (!err && data.status === "0") {
//         const { uptime, text } = data.result.now;
//         resolve({ uptime, text });
//       } else {
//         message.error("获取天气失败");
//       }
//     });
//   });
// };

// reqWeather(420100);
